<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('详细入库信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fEnter-edit" th:object="${fEnter}">
            <input name="enterId" th:field="*{enterId}" type="hidden">
            <input name="thingId" th:field="*{thingId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">物品目录：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input readonly="readonly" required name="thingName" th:field="*{thingName}"  id="treeName" type="text" placeholder="请选择物品" class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                    <span style="color: red" id="tishi"></span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">物品名称：</label>
                <div class="col-sm-8">
                    <input name="createName" th:field="*{createName}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">单价：</label>
                <div class="col-sm-8">
                    <input id="danjia"  required name="danjia" th:field="*{danjia}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">数量：</label>
                <div class="col-sm-8">
                    <input id="shuliang"  required name="shuliang" th:field="*{shuliang}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">总额：</label>
                <div class="col-sm-8">
                    <input id="zonge" name="zonge" th:field="*{zonge}" class="form-control" type="number">
                </div>
            </div>
            <div id="freasonDiv" style="display: none" class="form-group">
                <label class="col-sm-3 control-label" style="color: red">超出平均单价理由：</label>
                <div class="col-sm-8">
                    <textarea id="freason" name="freason" class="form-control">[[*{freason}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">入库类型：</label>
                <div class="col-sm-8">
                    <select name="enterType" class="form-control m-b" th:with="type=${@dict.getType('f_enter_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{enterType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">入库时间：</label>
                <div class="date col-sm-8">
                    <input name="enterTime" type="text" th:value="*{#dates.format(enterTime, 'yyyy-MM-dd')}" class="form-control" id="enterTime" placeholder="yyyy-MM-dd" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">平均单价：</label>
                <div class="col-sm-8">
                    <input name="averageDanjia" th:field="*{averageDanjia}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发票号：</label>
                <div class="col-sm-8">
                    <input name="lnvoiceNumber" th:field="*{lnvoiceNumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="imgList" th:field="*{imgList}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="imgList" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>

            <div id="examineBy" style="display: none;" class="form-group">
                <label class="col-sm-3 control-label">审批人：</label>
                <div class="col-sm-8">
                    <p class="form-control-plaintext" th:text="*{examineBy}"></p>
                </div>
            </div>
            <div id="examineRemark" style="display: none;" class="form-group">
                <label class="col-sm-3 control-label">审批意见：</label>
                <div class="col-sm-8">
                    <p class="form-control-plaintext" th:text="*{examineRemark}"></p>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var fEnter = [[${fEnter}]]
        if(fEnter.examineRemark){
            $("#examineRemark").css("display","block")
        }
        if(fEnter.examineBy){
            $("#examineBy").css("display","block")
        }
        if(fEnter.freason){
            $("#freasonDiv").css("display","block")
        }

        var prefix = ctx + "financial/fEnter";
        $("#form-fEnter-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-fEnter-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                showRemove:false,
                showUpload:false,
                showCaption:false,
                showCancel:false,
                showBrowse:false
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

    </script>
</body>
</html>